-
Notifications
You must be signed in to change notification settings - Fork 166
Add espnow #483
base: Dev
Are you sure you want to change the base?
Add espnow #483
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have started to check your change, many thanks for the contribution ! Please check my comments and questions.
esp32/mods/esp_espnow.c
Outdated
|
||
STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { | ||
|
||
mp_obj_espnow_t *self = m_new_obj(mp_obj_espnow_t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better if this class would be "singleton", like e.g. CoAp module. As I understand instantiating again this class would result that esp_now is re-initialized which may ruin the already ongoing former instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - I agree - perhaps like this??
// A static pointer to the espnow singleton
STATIC mp_obj_espnow_t *espnow_singleton = NULL;
STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
if (espnow_singleton != NULL) {
return espnow_singleton;
}
mp_obj_espnow_t *self = m_new_obj(mp_obj_espnow_t);
self->base.type = type;
self->number = 0;
ESPNOW_EXCEPTIONS(esp_now_init());
ESPNOW_EXCEPTIONS(esp_now_register_recv_cb(recv_cb));
ESPNOW_EXCEPTIONS(esp_now_register_send_cb(send_cb));
espnow_singleton = self;
return MP_OBJ_FROM_PTR(self);
}
l
esp32/mods/esp_espnow.c
Outdated
if (encrypt) _get_bytes(key, ESP_NOW_KEY_LEN, peer.lmk); | ||
if (re_add) { | ||
// workaround for calling esp_now_mod_peer() to | ||
// change encryption status will crash the system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why does it cause crash ?
esp32/mods/esp_espnow.c
Outdated
// this workaround enables ESP32 to send from whatever IF that is | ||
// active | ||
// if_id == wifi_mode - 1 | ||
#define IS_IF_AVAILABLE(mode, if_id) ({ (mode & (if_id+1)) != 0; }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see the purpose of these 2 macros, I think it would just enough to check whether the WLAN is initialized or not. Does it matter whether the mode is STA or AP ?
esp32/mods/esp_espnow.c
Outdated
// The variable has been changed to not static to make it visble outside the wlan module. | ||
// TODO - change to public call | ||
|
||
//extern bool wifi_started; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please if not needed remove these lines.
esp32/mods/esp_espnow.c
Outdated
if (addr == mp_const_none) { | ||
// send to all | ||
esp_now_peer_info_t peer; | ||
esp_err_t e = esp_now_fetch_peer(true, &peer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, wouldn't it be enough to call esp_now_send() with NULL as peer_addr? As far I understand in that case it sends out the packet to all available peers.
@rodgergr : thanks for the contribution, esp-now module will be part of a future release. |
Hi Geza,
Thank you for your help.
I have been holding off progressing ESPNOW over the last few weeks as it has been significantly enhanced and updated by a contributor to the main MicroPython project and now includes ring buffers to make it more resilient and to avoid the need to use callbacks. There are also a number of other significant improvements.
I have ported this new version to the Pycom environment and am currently testing and debugging it.
When complete, should I issue a new PR? Or do you already have it covered?
…Sent from my iPad
On 27/01/2021, at 5:12 AM, Géza Husi ***@***.***> wrote:
@rodgergr : thanks for the contribution, esp-now module will be part of a future release.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@rodgergr : yes please append it here and then we can check it and decide what to do. By default I think it should be kept simple, what is the problem with the callbacks? |
@geza-pycom The following are the key changes with the enhanced version of ESPNow. The ability to use ESPNow inside of an asyncio environment would be most beneficial. Callbacks are still used internally, but no longer exposed.
|
@geza-pycom I have now merged in the latest changes from the micropython version by glenn20 and this substantially improves the performance and stability of espnow. I have not been able to squash the commits very well, but the key files can be found in esp32/mod and are espnow.c, ringbuffer.c and ringbuffer.h. I also added espnow error codes in esp32/mp_pycom_err.h. Initial tests show that the espnow methods successfully send and receive espnow packets as expected. Please advise next steps. |
Hi |
Hello! |
Added espnow class to Pycom code based on earlier work done by Nick Moore and shawwwn for generic micropython.
Main changes involved adopting the Pycom approach to callbacks using mp_irq_queue_interrupt() in the ISR routine to route the data to an appropriate queue handler and converted to be a Class.
The proper object oriented (Class) version of espnow is in mods/ , but an earlier more primitive version has been left in the esp32 root directory for information only and should be removed before merging.
TODO: detection of wifi status at line 253 of espnow is not implemented yet and could be improved by someone with greater familiarity of the wifi code.